/*
 * Copyright 2007 Google Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
 * use this file except in compliance with the License. You may obtain a copy of
 * the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0

 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the

 * License for the specific language governing permissions and limitations under
 * the License.
 */
package com.google.gwt.util.compat;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Set;
import javax.lang.model.element.Modifier;

public class ClassNode implements Comparable<ClassNode> {
  List<FieldNode> fields = new ArrayList<FieldNode>();
  List<String> ifaces = new ArrayList<String>();
  List<MethodNode> methods = new ArrayList<MethodNode>();
  Set<Modifier> mods;
  String pkgName;
  String name;
  String parent = "none";
  
  public ClassNode(String pkg, String classname, Set<Modifier> modifiers) {
    pkgName = pkg;
    name = classname;
    mods = modifiers;
  }
  
  public ClassNode(String pkg, String classname) {
    this(pkg, classname, null);
  }
  
  public ClassNode copy() {
    return new ClassNode(pkgName, name, mods);
  }
  
  void addInterface(String iface) {
    ifaces.add(iface);
  }
  
  void addField(FieldNode field) {
    fields.add(field);
  }
  
  void addMethod(MethodNode method) {
    methods.add(method);
  }
  
  void setParent(String p) {
    parent = p;
  }
  
  public String toString() {
    String ret = pkgName + " . " + name;
/*    for (Modifier m : mods)
      ret += m.toString() + " ";
    ret += pkgName + " . " + name;
    if (parent != null)
      ret += " extends " + parent;
    if (ifaces != null) {
      ret += " implements ";
      for (String iface : ifaces)
        ret += iface + ", ";
    }
    ret += "\n";
    if (fields != null)
      for (FieldNode f : fields)
        ret += f.toString() + "\n";
    if (methods != null)
      for (MethodNode m : methods)
        ret += m.toString() + "\n";*/
    return ret;
  }

  public int compareTo(ClassNode o) {
    int testPkg = pkgName.compareTo(o.pkgName);
    if (testPkg != 0)
      return testPkg;
    return name.compareTo(o.name);
  }
  
  public boolean equals(Object o) {
    return compareTo((ClassNode) o) == 0;
  }
  
  void done() {
    Collections.sort(fields);
    Collections.sort(ifaces);
    Collections.sort(methods);
  }
  
}
